package com.briup.day18;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * 实现java对象 序列化 反序列化
 * @author lining
 * @date 2024/1/30 11:48
 */
public class TestTransient {
    public static void main(String[] args) throws Exception{
        //1.声明2个流 序列化 反序列化
        ObjectOutputStream oos =
                new ObjectOutputStream(
                        new FileOutputStream("d.txt"));
        ObjectInputStream ois =
                new ObjectInputStream(new FileInputStream("d.txt"));

        Student s = new Student(1, "jack", "昆山");
        oos.writeObject(s);
        oos.flush();
        oos.close();
        //读操作：
        Object o = ois.readObject();
        System.out.println("反序列化获取学生信息："+o);


    }
}
